﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;
/// <summary>
///URLUtil 的摘要说明
/// </summary>
public class URLUtil
{
    private const string AreaStr = "AreaIDStr";

    public static SuperviseQuery GetSuperviseQueryFromURL(System.Web.HttpRequest Request)
    {
        //System.Web.HttpContext.Current.Request
        System.Collections.Specialized.NameValueCollection col = Request.QueryString;

        string sessionid = string.Empty;
        if (Request.QueryString["sessionid"] != null)
        {
            sessionid = Request.QueryString["sessionid"].ToString();
        }
        SuperviseQuery result = null;
        if (sessionid != "")
        {
            result = (SuperviseQuery)System.Web.HttpContext.Current.Session[sessionid];
        }
        //释放
        //System.Web.HttpContext.Current.Session.Remove(sessionid);

        if (result == null)
        {
            result = new SuperviseQuery();

            //第一次加载 默认地区是该用户你能够查询的地区的全部 这里与查询控件结合 空表示全部 然后在 Appen里面加上限制条件
            //string areaId = (CurrentAccount.GetUser().Org.Area.AreaID == CurrentAccount.GetCurrentDeployArea().AreaID) ? "" : CurrentAccount.GetUser().Org.Area.AreaID;
            //result.AreaID = areaId;  //CurrentAccount.GetUser().AreaID ;//帮当前用户的可查询的地区编号输入
            //result.Append = " AreaID IN ('" + AreaID.Replace("'", "").Replace(",", "','") + "') ";
        } 

        return result;
    }

    public static string AreaID
    {
        get
        {
            string areaidstr = string.Empty;

            if (HttpContext.Current.Session[AreaStr] == null)
            {
                HZ.Supervise.Model.User user = CurrentAccount.GetUser();
                IBLL_Area ia = new HZ.Supervise.BLL.BLL_Area();
                IList<Area> lstArea = new List<Area>();
                string AreaID = user.Org.Area.AreaID;
                int i;
                if (AreaID.Split(',').Length == 1 && AreaID.Substring(2, 4) == "0000")
                {
                    lstArea = ia.GetSonAreas(AreaID,1,0,out i);
                    foreach (Area area in lstArea)
                    {
                        areaidstr += "," + area.AreaID;
                    }
                    areaidstr += "," + AreaID; //省直属   
                }
                else
                {
                    lstArea = ia.GetAreasByAreaID(AreaID);
                    foreach (Area area in lstArea)
                    {
                        areaidstr += "," + area.AreaID;
                    }
                }
                HttpContext.Current.Session[AreaStr] = areaidstr.Substring(1, areaidstr.Length - 1);
            }
            return HttpContext.Current.Session[AreaStr] as string;
        } 
        set
        {
            HttpContext.Current.Session[AreaStr] = null;
        }
    }
}

